"""
该文件用于 公共页面
"""
import time
import pyautogui
from common_ai_img import AIButton,Icon,OcrText
from page.scan_mode_page import ScanModePage
from page.main_page import MainPage
from page.scan_page import ScanPage
from page.edit_page import EditPage
from page.mesh_page import MeshPage
from page.save_page import SavePage
from utils.utils_operation import cal_ratio
from utils.utils_log import loggerCase

class CommonPage(MainPage, ScanModePage, ScanPage, EditPage, MeshPage, SavePage):
    """公共页面"""
    def click_confirm_button(self, max_wait_time=3):
        """确定"""
        loggerCase.info("确定")
        self.click(AIButton(OcrText("Confirm")), max_wait_time=max_wait_time)
        self.loading()

    def click_preview_button(self, max_wait_time=3):
        """预览"""
        loggerCase.info("预览")
        self.click(AIButton(OcrText("Preview")), max_wait_time=max_wait_time)
        self.loading()

    def click_yes_button(self, max_wait_time=3):
        """
        点击yes按钮
        :return:
        """
        loggerCase.info("点击yes按钮")
        self.click(AIButton(OcrText("Yes")), max_wait_time=max_wait_time)
        self.loading()

    def click_no_button(self, max_wait_time=3):
        """
        点击no按钮
        :return:
        """
        loggerCase.info("点击no按钮")
        self.click(AIButton(OcrText("No")), max_wait_time=max_wait_time)

    def click_apply_button(self, max_wait_time=3):
        """
        点击应用按钮
        :return:
        """
        loggerCase.info("点击应用按钮")
        self.click(AIButton(OcrText("Apply")), max_wait_time=max_wait_time)
        self.loading()

    def click_next_button(self, max_wait_time=3):
        """
        点击下一步按钮
        :return:
        """
        loggerCase.info("点击下一步按钮")
        self.click(AIButton(OcrText("Next")), max_wait_time=max_wait_time)

    def click_exit_button(self, max_wait_time=3):
        """
        点击退出按钮
        :return:
        """
        loggerCase.info("点击退出按钮")
        self.click(AIButton(OcrText("Exit")), max_wait_time=max_wait_time)

    def click_cancel_button(self, max_wait_time=5):
        """
        点击取消按钮
        :return:
        """
        loggerCase.info("点击取消按钮")
        self.click(AIButton(OcrText("Cancel")), max_wait_time=max_wait_time)

    def click_clear_all_button(self, max_wait_time=3):
        """
        点击clearall按钮
        :return:
        """
        loggerCase.info("点击清空按钮")
        self.click(AIButton(OcrText("Clear all")), max_wait_time=max_wait_time)

    def common_flow_path(self, mode, file_name, path=None):
        """
        创建工程
        mode: LASER ; Trak
        file_name:文件名
        """
        time.sleep(1)
        if mode == "Laser":
            self.click_laser_mode()
        elif mode == "IR":
            self.click_ir_mode()
        if path == "desktop":
            self.click_browse_button()
            self.click_desktop_button()
            self.click_select_button()
        time.sleep(5)
        self.edit_name_editor(file_name)
        self.ENTER()
        # if self.is_has_notice(text="文件覆盖警告框"):
        self.ENTER()


    def edit_choose_date(self, origin_x=500, origin_y=660, target_x=1300, target_y=800):
        """
        编辑选中数据
        """
        origin_x = int(origin_x)
        origin_y = int(origin_y)
        target_x = int(target_x)
        target_y = int(target_y)
        ratio = cal_ratio()
        pyautogui.moveTo(x=origin_x * ratio, y=origin_y * ratio)
        pyautogui.keyDown('shift')
        pyautogui.dragTo(x=target_x * ratio, y=target_y * ratio, duration=1)
        pyautogui.keyUp('shift')
        time.sleep(3)

    def scroll_down(self):
        """下滑鼠标"""
        pyautogui.scroll(-1000)

    def create_scan_flow_path(self, scan_time=30):
        """
        扫描流程
        """
        scan_time = int(scan_time)
        # 扫描标志点
        if self.judge_exist_preview_button():
            self.click_preview_scan_button()
        self.click_scan_button(max_wait_time=5)
        time.sleep(scan_time)
        self.click_pause_button(max_wait_time=3)



if __name__ == '__main__':
    page = CommonPage()
    page.click_new_project_group()
    page.common_flow_path("Laser")